<?php
/**
* Desc
*
* @link http://webappkit.net
* @package pathnodes
* @subpackage zip
* @author J.Ducastel <nospam0@ducastel.name>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
/**
* registers as pathnode subclass
*/
pathnode::heritage('zipFileNode',10);

/**
*
* @uses PclZip
* @uses zipChildNode
*/
class zipFileNode extends archiveNode {
/*--------------------------------------------------------------------
CONSTRUCTOR
--------------------------------------------------------------------*/
    /**
    * constructor alias
    * @access public
    * /
    function zipNode($path) {
        $this->__construct($path);
    }/**/
    
    /**
    * "real" constructor
    * @access public
    * @param string $path
    * /
    function __construct($path) {
        // getting base info
        $this->setInfo();
        // trying to build PclZip instance
        //if ($this->)
    }/**/
/*--------------------------------------------------------------------
PUBLIC STATIC METHODS
--------------------------------------------------------------------*/
    /**
    * 
    * @static
    * @param
    * @return 
    * /
    function () {
        
    }/**/
/*--------------------------------------------------------------------
PUBLIC INSTANCE METHODS
--------------------------------------------------------------------*/
    /**
    * is a valid zip node ?
    * @access public
    * @return bool
    */
    function isValid() {
        $z=$this->_pclzip();
        if (!is_a($z,'pclzip'))
            return false;
        $prop=$z->properties();
        return $prop and $prop['status']=='ok';
    }/**/
    
    /**
    * sets node children if necessary and returns them
    * @access public
    * @return array of pathNode derived instances
    */
    function & getChildren() {
        $false=false;
        if (!$this->exists()) return $false;
        if (!$this->children) {
   $z=$this->_pclZip();
            $files=$z->listContent(); //echo '<pre>'; print_r($files);
            foreach ($files as $info) {
                $child=new zipChildNode($this);
                $child->index($info['index']);
                $child->size($info['size']);
                $child->storedSize($info['compressed_size']);
                $child->filename($info['filename']);
                $child->storedFilename($info['stored_filename']);
                $child->isFolder($info['folder']);
                $child->mtime($info['mtime']);
                $child->comment($info['comment']);
                $key=$child->storedFileName();
                $this->children[$key]=$child;
            }
        }
        return $this->children;
    }/**/

    /**
    * extracts a child by index
    * @param int $index
    * @access public
    * @return string
    */
    function extractByIndex($index) {
        // $this->getChildren();
        $Z=&$this->_pclZip(); // echo $index;
        $result=$Z->extractByIndex($index,PCLZIP_OPT_EXTRACT_AS_STRING);
        //echo '<pre>'; print_r($result);
        return $result[0]['content'];
    }/**/

    /**
    *
    * @param
    * @access public
    * @return
    * /
    function () {

    }/**/
/*--------------------------------------------------------------------
VARS / MEMBERS
--------------------------------------------------------------------*/
    /**
    * @var PclZip mapped library instance
    */
    var $_pclZip;
    
/*--------------------------------------------------------------------
PRIVATE / PROTECTED METHODS
--------------------------------------------------------------------*/
    /**
    * 
    * @param
    * @access protected
    * @return 
    */
    function selfDetector($path) {
        return ereg('\.zip$',$path);
    }/**/
    
    /**
    * returns PclZip instance
    * @access protected
    * @return PclZip
    */
    function & _pclZip() {
        if (!$this->_pclZip) {
            $this->_pclZip=new PclZip($this->path);
        }
        return $this->_pclZip;
    }/**/
    
        /**
    * 
    * @param
    * @access protected
    * @return 
    * /
    function () {
        
    }/**/
}
?>